import 'dart:async';

import 'package:course_control/app/routes/app_pages.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class StartController extends GetxController {
  final timeStr = ''.obs;
  final dateTimeStr = ''.obs;
  late Timer _timer;
  @override
  void onInit() {
    super.onInit();
    initData();
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      initData();
    });
  }

  initData() {
    var format = DateFormat('HH:mm');
    var dateFormat = DateFormat('MM月dd日 EEE', 'zh_CN');
    var date = DateTime.now();
    timeStr.value = format.format(date);
    dateTimeStr.value = dateFormat.format(date);
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
    _timer.cancel();
  }

  void onStartCourse() {
    Get.toNamed(Routes.TABBAR);
  }
}
